package com.study.security.core.validate.code.config;

import com.study.security.core.properties.SecurityProperties;
import com.study.security.core.validate.code.generator.ValidateCodeGenerator;
import com.study.security.core.validate.code.impl.image.generator.ImageValidateCodeGenerator;
import com.study.security.core.validate.code.impl.sms.SmsCodeSender;
import com.study.security.core.validate.code.impl.sms.impl.DefaultSmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liyongkui
 */
@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    private SecurityProperties securityProperties;

    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ImageValidateCodeGenerator imageValidateCodeGenerator(){
        ImageValidateCodeGenerator validateCodeGenerator = new ImageValidateCodeGenerator();
        validateCodeGenerator.setSecurityProperties(securityProperties);
        return validateCodeGenerator;
    }

    @Bean
    @ConditionalOnMissingBean(SmsCodeSender.class)
    public SmsCodeSender smsCodeSender(){
        return new DefaultSmsCodeSender();
    }
}
